      SUBROUTINE RDREQMT5A2(LUREQMT,IEXP,MAXEXP,MAXTGT,MAXREQTGT,
     *           CH8NAME,REQTGT,NUMTGT,LUERR,IERR)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C THIS ROUTINE IS PART OF THE TOSS REQUIREMENTS FILE READER PACKAGE. IT
C READS TARGET-SPECIFIC DATA. DATA STORAGE OCCURS HERE IF NECESSARY(IE,
C WHEN IEXP>0).  ERROR CHECKS ALSO.
C
C***********************************************************************
C
C BY C PETRUZZO GSFC/742  1/86
C        MODIFIED....
C
C***********************************************************************
C
      INCLUDE 'RDREQMT.INC'
C
      INTEGER*4   NUMTGT(MAXEXP)
      REAL*8      REQTGT(MAXREQTGT,MAXTGT,MAXEXP)
      CHARACTER*5 I4CHAR,CHTEMP1,CHTEMP2
      CHARACTER*8 CH8NAME
C
      REAL*8 PARMS(MAXPARMS)
      REAL*8    R8VAL/1234567.D0/
      INTEGER*4 I4VAL/1234567/
C
C
      NUMTARGS = 0
      IERR = 0
C
C
      ID = 0
      NTARGS = 0
      DO WHILE (ID.NE.-9999)
        CALL MTXSETR8(PARMS,R8VAL,MAXPARMS,1)
        READ(LUREQMT,*,END=310) PARMS
        ID = JIDNNT(PARMS(1))
C
C      IF TARGETS FOR THIS EXPERIMENT HAVE NOT ENDED AND IF THIS IS A
C      DATA-SAVING CALL, LOAD THE DATA.
C
        IF(ID.GT.0 .AND. IEXP.GT.0) THEN
C
C        ERROR CHECK.
          IF(ID.EQ.I4VAL) THEN
            IERR = 1
            IF(LUERR.GT.0) WRITE(LUERR,9901)
     *        'REQMT FILE HAS RECORD WITH NO TARGET ID.' //
     *          '  EXPMT= ' // CH8NAME
            GO TO 9999
            END IF
C
          IF(NTARGS.LT.MAXTGT) THEN
            NTARGS = NTARGS + 1
            REQTGT(1,NTARGS,IEXP) = ID
C          ERROR CHECK. BE SURE RECORD HAD NO PARAMETER VALUES AT
C          ARRAY POSITIONS LARGER THAN WHAT THE CALLER HAS ALLOCATED.
            IF(MAXPARMS.GT.MAXREQTGT) THEN
              DO I=MAXREQTGT+1,MAXPARMS
                IF(PARMS(I).NE.R8VAL) THEN
                  IERR = 4
                  CHTEMP1= I4CHAR(MAXEXP,5,K1)
                  CHTEMP2= I4CHAR(MAXEXP,5,K2)
                  IF(LUERR.GT.0) WRITE(LUERR,9901)
     *             'TOO MANY PARAMETERS FOR TARGET ID ' // CHTEMP1(K1:5)
     *                   // '.   EXPMT=' // CH8NAME,
     *             '  YOUR PROGRAM ALLOWS MAX= ' // CHTEMP2(K2:5)
                  GO TO 9999
                  END IF
                END DO
              END IF
C          PUT WHATEVER IS PRESENT IN THE RECORD INTO OUTPUT ARRAY
            IF(MAXREQTGT.GT.1) THEN  !HAVE ALREADY LOADED THE FIRST(=ID)
              DO I=2,MAXREQTGT
                IF(PARMS(I).NE.R8VAL) REQTGT(I,NTARGS,IEXP) = PARMS(I)
                END DO
              END IF
          ELSE
C          ERROR. TOO MANY TARGETS ON THE FILE.
            IERR = 2
            CHTEMP1 = I4CHAR(MAXTGT,5,K1)
            IF(LUERR.GT.0) WRITE(LUERR,9901)
     *        'TOO MANY TARGETS FOR EXPERIMENT NAMED ' // 
     *            CH8NAME // '  MAX=' // CHTEMP1(K1:5)
            GO TO 9999
            END IF
          END IF
        END DO
      GO TO 9999
C
C
C ERROR CONDITION. END-FILE SENSED BEFORE 'ENDREQ' WAS READ OR BEFORE
C ID=-9999 WAS READ. RDREQMT HAS ALREADY TESTED THE FILE AND FOUND IT
C OK. TO GET HERE, AN ERROR IS PRESENT SOMEWHERE. STOP THE RUN TO
C FORCE A LOOK THE ERROR.
C
  310 CONTINUE
      STOP 'CODING ERROR. RUN STOPPED. SEE SOURCE CODE IN RDREQMT5A2.'
C
C WRAP UP.
C
 9999 CONTINUE
C
      IF(IEXP.GT.0) THEN
C      WE WERE LOOKING FOR THIS EXPERIMENT. IF NO ERROR, RESET
C      NUMTGT(IEXP). IF ERROR, NUMTGT(IEXP) REMAINS AT -1(AS SET IN
C      RDREQMT) SO CALLER TO RDREQMT CAN IDENTIFY EXPMTS NOT LOADED OK.
        IF(IERR.EQ.0) NUMTGT(IEXP) = NTARGS
        END IF
      RETURN
C
 9901 FORMAT(/,
     *   ' OBSERVATION REQUIREMENTS FILE READER. ERROR CONDITION.'/,
     *   (5X,A))    ! ERROR MESSAGE TEXT
      END
